var app = getApp();

Page({
  data: {
    expresses: [],
    pageNum: 1,
    pageSize: 5,
    keyword: null,

    no_more: false, //没有更多了
  },
  onLoad() {
    
  },
  onShow() {
    this.setData({
      expresses: [],
      pageNum: 1,
      pageSize: 5,
      keyword: null
    })
    this.selectExpressByPage()
  },
  onReachBottom () {
    // 页面被拉到底部
    console.log('页面被拉到底部了')
    this.setData({
      pageNum: this.data.pageNum + 1
    })
    dd.httpRequest({
      url: app.globalData.url + '/express/list',
      data: {
        pageNum: this.data.pageNum,
        pageSize: this.data.pageSize,
        keyword: this.data.keyword
      },
      dataType: 'json',
      success: (res) => {
        console.log('success----', res)
        // dd.alert({ content: JSON.stringify(res) });
        if(res.data.data === null || res.data.data.length === 0){
          this.setData({
            no_more: true
          })
        } else {
          this.setData({
            expresses: this.data.expresses.concat(res.data.data)
          })
        }
      },
      fail: (res) => {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: (res) => {
        dd.hideLoading();
      }
    });
  },
  detail(e) {
    console.log("details-----" + e)
    dd.navigateTo({
      url: "/pages/express/expressDetail/expressDetail?expressId=" + e.currentTarget.id
    })
  },
  search(){
    this.setData({
      expresses: [],
      pageNum: 1,
      pageSize: 5,
      no_more: false
    })
    this.selectExpressByPage()
  },
  inputInfo(event) {
    this.setData({
      keyword: event.detail.value
    })
  },
  selectExpressByPage: function () {
    dd.httpRequest({
      url: app.globalData.url + '/express/list',
      data: {
        pageNum: this.data.pageNum,
        pageSize: this.data.pageSize,
        keyword: this.data.keyword
      },
      dataType: 'json',
      success: (res) => {
        console.log('success----', res)
        // dd.alert({ content: JSON.stringify(res) });
        this.setData({
          expresses: res.data.data
        })
      },
      fail: (res) => {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: (res) => {
        dd.hideLoading();
      }
    });
  }
});
